<?php
/**
* SimpleDropDownList.php
*
* Contains SimpleDropDownList class definition
* @author  John Snook <jsnook@gmail.com>
* @version 2
* @copyright (c) Snook 2004
* @package QuickDataFiles
*/

/**
* SimpleDropDownList
*
* This class allows a user to bind an array to a drop down list via SimpleDropDownList::ListArray.
* @author  John Snook <jsnook@gmail.com>
* @version 2
* @copyright (c) Snook 2004
* @example /var/www/corp/IntraDox/Documents.php
* @todo Add ability to handle image drop downs.
* @package QuickData
* @subpackage QuickDataFields
*/
class SimpleDropDownList extends OneToMany
{
	var $ListArray;	
	// expects $Caption, $LocalField, $ListArray
	function SimpleDropDownList($Properties)
	{
		parent::OneToMany($Properties);
//		$this->ListArray = $ListArray;
		$this->CanSearch = FALSE;
	}

	function GetSQLReadyValue()
	{
		return parent::GetSQLReadyValue();
	}

	function Update()
	{
		parent::Update();
	}		

	function Render($DataRow, $DisplayMode = QD_MODE_VIEW)
	{
		$this->Value = $DataRow[$this->LocalField];
		$out .= "\t<tr>\n\t\t<td class=\"" . $this->Parent->ViewCaptionCssClassName . "\">$this->Caption</td>\n";
		$out .= "\t\t<td class=\"" . $this->Parent->ViewCssClassName . "\">";
		if (count($this->ListArray) == 0)
		{
			die("Listarray is 0 in SimpleDropDownList");
		}
		switch($DisplayMode)
		{
			case QD_MODE_EDIT:
			case QD_MODE_ADD:
				$out .= "\t\t<select class=\"" . $this->Parent->EditCssClassName . "\" name=\"$this->LocalField\">\n";
				if ( $this->IncludeNone ) // lets make the first one null if they want to
				{
					$out .= "\t\t\t<option value=\"\">None</option>";
				}
				// loop through our list
				foreach($this->ListArray as $key => $value)
				{
					$out .= "\t\t\t<option ";
					if ($this->Value == $key)
					{
						$out .= "selected ";
					}
					$out .= " value=\"" . $key . "\">" . $value . "</option>\n";
				}
				$out .= "\t\t</select>";
				break;
			case QD_MODE_VIEW:
				$out .= $this->ListArray[$this->Value];
				break;
		}
		$out .= "</td>\n\t</tr>\n";
		return $out;
	}
}
?>